package sistemasdistribuidos;

import java.awt.event.KeyEvent;
import java.math.BigDecimal;
import java.math.RoundingMode;
import telasMensagem.Bloqueio;

public class FecharVenda extends javax.swing.JDialog {

    String antigo = null;
    double falta = 0;
    double troco = 0;
    double recebido = 0;
    static double total;
    String caracteres = "0987654321.";
    static BigDecimal bd;

    public FecharVenda(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    public FecharVenda(java.awt.Frame parent, boolean modal, double venda) {
        super(parent, modal);
        initComponents();
        falta = venda;
        total = venda;
        jTextFieldFalta.setText(String.valueOf(venda));
        jTextFieldTotal.setText(String.valueOf(venda));
        jTextFieldFalta.setEditable(false);
        jTextFieldRecebido.setEditable(false);
        jTextFieldTotal.setEditable(false);
        jTextFieldTroco.setEditable(false);
    }

    public void contas() {
        try {
            double cheque = 0;
            double credito = 0;
            double debito = 0;
            double dinheiro = 0;

            if (jTextFieldCheque.getText().length() > 0) {
                cheque = Double.valueOf(jTextFieldCheque.getText());
            }
            if (jTextFieldCredito.getText().length() > 0) {
                credito = Double.valueOf(jTextFieldCredito.getText());
            }
            if (jTextFieldDebito.getText().length() > 0) {
                debito = Double.valueOf(jTextFieldDebito.getText());
            }
            if (jTextFieldDinheiro.getText().length() > 0) {
                dinheiro = Double.valueOf(jTextFieldDinheiro.getText());
            }
            recebido = cheque + credito + debito + dinheiro;
            total = Double.valueOf(jTextFieldTotal.getText());
            falta = total - recebido;
            bd = new BigDecimal(recebido).setScale(2, RoundingMode.HALF_EVEN);
            jTextFieldRecebido.setText(String.valueOf(bd));
            if (falta == recebido || falta < recebido) {
                jTextFieldFalta.setText("0.00");
            }
            if (recebido > total) {
                troco = (recebido - total);
                bd = new BigDecimal(troco).setScale(2, RoundingMode.HALF_EVEN);
                jTextFieldTroco.setText(String.valueOf(bd));
            }
        } catch (Exception ex) {
            Bloqueio bl = new Bloqueio(null, true, "<html>Valor inválido inserido!                      <br>"
                    + " Por favor, adicione apenas números neste campo,"
                    + " separando os centavo por ponto (`.`)</html>");
            bl.setLocationRelativeTo(null);
            bl.setVisible(true);
        }
    }

    public void apagar(Double retirado) {

        if (retirado >= troco) {
            troco = 0;
            jTextFieldTroco.setText("0.00");
        } else {
            troco = troco - retirado;
            jTextFieldTroco.setText(String.valueOf(troco));
        }
        recebido = recebido - retirado;
        jTextFieldRecebido.setText(String.valueOf(recebido));
        if (retirado == recebido) {
            falta = total;
        } else {
            if (recebido > total) {
                falta = -1 * (total - recebido);
            } else {
                falta = total - recebido;
            }
        }
        if (recebido > total) {
            falta = 0;
        }
        jTextFieldFalta.setText(String.valueOf(falta));
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabelMsg7 = new javax.swing.JLabel();
        jLabelMsg8 = new javax.swing.JLabel();
        jLabelMsg10 = new javax.swing.JLabel();
        jLabelMsg18 = new javax.swing.JLabel();
        jButtonConcluir = new javax.swing.JButton();
        jTextFieldDinheiro = new javax.swing.JTextField();
        jTextFieldCheque = new javax.swing.JTextField();
        jTextFieldDebito = new javax.swing.JTextField();
        jTextFieldCredito = new javax.swing.JTextField();
        jPanel4 = new javax.swing.JPanel();
        jLabelMsg3 = new javax.swing.JLabel();
        jLabelMsg5 = new javax.swing.JLabel();
        jTextFieldFalta = new javax.swing.JTextField();
        jTextFieldRecebido = new javax.swing.JTextField();
        jLabelMsg4 = new javax.swing.JLabel();
        jTextFieldTotal = new javax.swing.JTextField();
        jLabelMsg2 = new javax.swing.JLabel();
        jTextFieldTroco = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Fechar Vendas");
        setAlwaysOnTop(true);

        jPanel1.setBackground(new java.awt.Color(255, 102, 0));
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, new java.awt.Color(0, 0, 0), new java.awt.Color(0, 0, 0), new java.awt.Color(0, 0, 0), new java.awt.Color(0, 0, 0)), "Valores Recebidos", javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI", 1, 14), new java.awt.Color(0, 0, 0))); // NOI18N
        jPanel1.setToolTipText("");

        jLabelMsg7.setFont(new java.awt.Font("Segoe UI", 1, 18)); // NOI18N
        jLabelMsg7.setText("Dinheiro:");

        jLabelMsg8.setFont(new java.awt.Font("Segoe UI", 1, 18)); // NOI18N
        jLabelMsg8.setText("Cheque:");

        jLabelMsg10.setFont(new java.awt.Font("Segoe UI", 1, 18)); // NOI18N
        jLabelMsg10.setText("Crédito:");

        jLabelMsg18.setFont(new java.awt.Font("Segoe UI", 1, 18)); // NOI18N
        jLabelMsg18.setText("Débito:");

        jButtonConcluir.setBackground(new java.awt.Color(255, 255, 255));
        jButtonConcluir.setFont(new java.awt.Font("Segoe UI", 0, 16)); // NOI18N
        jButtonConcluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/pata.png"))); // NOI18N
        jButtonConcluir.setText("Concluir");
        jButtonConcluir.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jButtonConcluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonConcluirActionPerformed(evt);
            }
        });

        jTextFieldDinheiro.setFont(new java.awt.Font("Segoe UI", 0, 16)); // NOI18N
        jTextFieldDinheiro.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextFieldDinheiroKeyReleased(evt);
            }
        });

        jTextFieldCheque.setFont(new java.awt.Font("Segoe UI", 0, 16)); // NOI18N
        jTextFieldCheque.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextFieldChequeKeyReleased(evt);
            }
        });

        jTextFieldDebito.setFont(new java.awt.Font("Segoe UI", 0, 16)); // NOI18N
        jTextFieldDebito.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextFieldDebitoKeyReleased(evt);
            }
        });

        jTextFieldCredito.setFont(new java.awt.Font("Segoe UI", 0, 16)); // NOI18N
        jTextFieldCredito.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextFieldCreditoKeyReleased(evt);
            }
        });

        jPanel4.setBackground(new java.awt.Color(255, 102, 0));
        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, new java.awt.Color(0, 0, 0), new java.awt.Color(0, 0, 0), new java.awt.Color(0, 0, 0), new java.awt.Color(0, 0, 0)), "Valores Recebidos", javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI", 1, 14), new java.awt.Color(0, 0, 0))); // NOI18N

        jLabelMsg3.setFont(new java.awt.Font("Segoe UI", 1, 18)); // NOI18N
        jLabelMsg3.setText("Falta:");

        jLabelMsg5.setFont(new java.awt.Font("Segoe UI", 1, 18)); // NOI18N
        jLabelMsg5.setText("Recebido:");

        jTextFieldFalta.setFont(new java.awt.Font("Segoe UI", 0, 16)); // NOI18N
        jTextFieldFalta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldFaltaActionPerformed(evt);
            }
        });

        jTextFieldRecebido.setFont(new java.awt.Font("Segoe UI", 0, 16)); // NOI18N
        jTextFieldRecebido.setText("0.00");

        jLabelMsg4.setFont(new java.awt.Font("Segoe UI", 1, 18)); // NOI18N
        jLabelMsg4.setText("Total:");

        jTextFieldTotal.setFont(new java.awt.Font("Segoe UI", 0, 16)); // NOI18N

        jLabelMsg2.setFont(new java.awt.Font("Segoe UI", 1, 18)); // NOI18N
        jLabelMsg2.setText("Troco:");

        jTextFieldTroco.setFont(new java.awt.Font("Segoe UI", 0, 16)); // NOI18N
        jTextFieldTroco.setText("0.00");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jTextFieldTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                        .addGap(0, 14, Short.MAX_VALUE)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabelMsg3)
                                    .addComponent(jLabelMsg5)
                                    .addComponent(jLabelMsg4))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jTextFieldFalta, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jTextFieldRecebido, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                                .addComponent(jLabelMsg2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jTextFieldTroco, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelMsg2)
                    .addComponent(jTextFieldTroco, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelMsg5)
                    .addComponent(jTextFieldRecebido, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldFalta, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelMsg3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelMsg4))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabelMsg8)
                            .addComponent(jLabelMsg18)
                            .addComponent(jLabelMsg10))
                        .addGap(27, 27, 27)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jTextFieldCheque, javax.swing.GroupLayout.DEFAULT_SIZE, 94, Short.MAX_VALUE)
                            .addComponent(jTextFieldDebito)
                            .addComponent(jTextFieldCredito)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabelMsg7)
                        .addGap(18, 18, 18)
                        .addComponent(jTextFieldDinheiro)))
                .addGap(35, 35, 35)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jButtonConcluir, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(26, 26, 26))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextFieldDinheiro, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabelMsg7))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextFieldCheque, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabelMsg8))
                        .addGap(12, 12, 12)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextFieldDebito, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabelMsg18))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabelMsg10)
                            .addComponent(jTextFieldCredito, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(1, 1, 1))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButtonConcluir, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(0, 10, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTextFieldFaltaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldFaltaActionPerformed

    }//GEN-LAST:event_jTextFieldFaltaActionPerformed

    private void jButtonConcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonConcluirActionPerformed
        if (falta != 0) {
            Bloqueio bl = new Bloqueio(null, true, "<html>Complete o"
                    + " valor total da venda antes de concluí-la! <html>");
            bl.setLocationRelativeTo(null);
            bl.setVisible(true);

        } else {

            /*

             Salvar venda!!!!
             ********** Banco de Dados ***********

             */
        }
    }//GEN-LAST:event_jButtonConcluirActionPerformed

    private void jTextFieldDinheiroKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldDinheiroKeyReleased
        String texto = String.valueOf(jTextFieldDinheiro.getText());      
        if (!caracteres.contains(evt.getKeyChar() + "") && !texto.equals(antigo)) {
            texto = texto.substring(0, texto.length() - 1);
            jTextFieldDinheiro.setText(texto);
        } else {
            antigo = texto;
            System.out.println(texto);
            jTextFieldDinheiro.setText(texto);
        }
        contas();

        /* String texto = jTextFieldDinheiro.getText();
         jTextFieldDinheiro.setText(null);
         if (evt.getKeyCode() == KeyEvent.VK_BACK_SPACE) {
         jTextFieldDinheiro.setText(null);
         } else {
         if (evt.getKeyCode() == KeyEvent.VK_PERIOD && texto.equals(".")) {
         jTextFieldDinheiro.setText("0.");
         } else {
         if (!caracteres.contains(evt.getKeyChar() + "") || texto.contains("..")) {
         texto = texto.substring(0, texto.length() - 1);
         jTextFieldDinheiro.setText(texto);
         } else {
         jTextFieldDinheiro.setText(texto);
         }
         }
         }
         contas();*/
    }//GEN-LAST:event_jTextFieldDinheiroKeyReleased

    private void jTextFieldChequeKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldChequeKeyReleased
        String texto = jTextFieldCheque.getText();
        jTextFieldCheque.setText(null);
        if (evt.getKeyCode() == KeyEvent.VK_BACK_SPACE) {
            jTextFieldCheque.setText(null);
        } else {
            if (evt.getKeyCode() == KeyEvent.VK_PERIOD && texto.equals(".")) {
                jTextFieldCheque.setText("0.");
            } else {
                if (!caracteres.contains(evt.getKeyChar() + "") || texto.contains("..")) {
                    texto = texto.substring(0, texto.length() - 1);
                    jTextFieldCheque.setText(texto);
                } else {
                    jTextFieldCheque.setText(texto);
                }
            }
        }
        contas();
    }//GEN-LAST:event_jTextFieldChequeKeyReleased

    private void jTextFieldDebitoKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldDebitoKeyReleased
        String texto = jTextFieldDebito.getText();
        jTextFieldDebito.setText(null);
        if (evt.getKeyCode() == KeyEvent.VK_BACK_SPACE) {
            jTextFieldDebito.setText(null);
        } else {
            if (evt.getKeyCode() == KeyEvent.VK_PERIOD && texto.equals(".")) {
                jTextFieldDebito.setText("0.");
            } else {
                if (!caracteres.contains(evt.getKeyChar() + "") || texto.contains("..")) {
                    texto = texto.substring(0, texto.length() - 1);
                    jTextFieldDebito.setText(texto);
                } else {
                    jTextFieldDebito.setText(texto);
                }
            }
        }
        contas();
    }//GEN-LAST:event_jTextFieldDebitoKeyReleased

    private void jTextFieldCreditoKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldCreditoKeyReleased
        String texto = jTextFieldCredito.getText();
        jTextFieldCredito.setText(null);
        if (evt.getKeyCode() == KeyEvent.VK_BACK_SPACE) {
            jTextFieldCredito.setText(null);
        } else {
            if (evt.getKeyCode() == KeyEvent.VK_PERIOD && texto.equals(".")) {
                jTextFieldCredito.setText("0.");
            } else {
                if (!caracteres.contains(evt.getKeyChar() + "") || texto.contains("..")) {
                    texto = texto.substring(0, texto.length() - 1);
                    jTextFieldCredito.setText(texto);
                } else {
                    jTextFieldCredito.setText(texto);
                }
            }
        }
        contas();
    }//GEN-LAST:event_jTextFieldCreditoKeyReleased

    public static void main(String args[]) {

        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FecharVenda.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FecharVenda.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FecharVenda.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FecharVenda.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                FecharVenda dialog = new FecharVenda(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonConcluir;
    private javax.swing.JLabel jLabelMsg10;
    private javax.swing.JLabel jLabelMsg18;
    private javax.swing.JLabel jLabelMsg2;
    private javax.swing.JLabel jLabelMsg3;
    private javax.swing.JLabel jLabelMsg4;
    private javax.swing.JLabel jLabelMsg5;
    private javax.swing.JLabel jLabelMsg7;
    private javax.swing.JLabel jLabelMsg8;
    public static javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel4;
    public static javax.swing.JTextField jTextFieldCheque;
    public static javax.swing.JTextField jTextFieldCredito;
    public static javax.swing.JTextField jTextFieldDebito;
    public static javax.swing.JTextField jTextFieldDinheiro;
    public static javax.swing.JTextField jTextFieldFalta;
    public static javax.swing.JTextField jTextFieldRecebido;
    public static javax.swing.JTextField jTextFieldTotal;
    public static javax.swing.JTextField jTextFieldTroco;
    // End of variables declaration//GEN-END:variables
}
